<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="/WEB-INF/jsp/includeTop.jsp" %>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>

<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td valign="top">
      <table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td valign="bottom" class="blueTableBg">&nbsp;默认模板管理</td>
        </tr>
				<%@ include file="/WEB-INF/jsp/plan/defaultTemplateSearch.jsp" %>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="5">
              <tr>
                <td>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="dashTopLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashTop" width=100%><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashTopRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td align="center">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
													<%@ include file="/WEB-INF/jsp/plan/defaultTemplateList.jsp" %>
                          <tr>
                            <td>
                              <table border="0" cellpadding="0" cellspacing="2">
                                <tr>
                                  <form id="formAdd" method="get" action="<c:url value="newDefaultTemplateForm.html"/>">
                                  <td><input type="button" class="btnStyle" value="  新增  " onclick="javascript:doAdd()"></td>
                                  </form>
                                  <c:if test="${!empty defaultTemplates}">
	                                  <form id="formEdit" method="get" action="<c:url value="enterDefaultTemplateEditForm.html"/>">
		                                  <input type="hidden" id="updatekey" name="updatekey">
		                                  <td><input type="button" class="btnStyle" value="  编辑  " onclick="javascript:doEdit()"></td>
	                                  </form>
	                                  <form id="formDelete" method="post" action="<c:url value="removeDefaultTemplate.html"/>">
		                                  <input type="hidden" id="keys" name="keys">
		                                  <td><input type="button" class="btnStyle" value="  删除  " onclick="javascript:doDelete()"></td>
	                                  </form>
	                                  <form id="formEnableDefault" method="post" action="<c:url value="enableDefaultTemplate.html"/>">
		                                  <input type="hidden" id="enableKey" name="enableKey">
		                                  <td><input type="button" class="btnStyle" value="  默认启用  " onclick="javascript:doEnableDefault()"></td>
	                                  </form>
                                  </c:if>
                                  </form>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table><p/>
                                  <c:if test="${!empty defaultTemplates}">
												<%@ include file="/WEB-INF/jsp/includePagedDisplay.jsp" %>
                                  </c:if>
                      </td>
                      <td class="dashRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashBottomLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashBottom" width=100%><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashBottomRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<script type="text/javascript">
	function doEnableDefault(){
		if(document.getElementsByName("cbIds") == null){
			return;
		}
		
		if(!checkAtLeastOne()){
			alert("请至少选择一条记录");
			return;
		}
		
		if(!checkOnlyOne()){
			alert("默认启用只能选择一个模板");
			return;
		}
	
		if (document.getElementsByName("cbIds").length == 1){
			if (document.getElementsByName("templateEnabledFlg")[0].value == "true") {
				alert("该模板已是默认模板，无需启用");
				return;
			}
			
			/*if (document.getElementsByName("msgTemplateCommunicationEnabledFlg")[0].value == "false" && 
				document.getElementsByName("voiceTemplateCommunicationEnabledFlg")[0].value == "false") {
				alert("该模板的短信或语音方式均未设定'通信启用'，无法启用作为默认模板");
				return;
			}*/
	
			document.getElementById("enableKey").value = document.getElementsByName("cbIds")[0].value;
		} else {
			for(var i=0;i<document.getElementsByName("cbIds").length;i++){
				if(document.getElementsByName("cbIds")[i].checked){
	
					if (document.getElementsByName("templateEnabledFlg")[i].value == "true") {
						alert("该模板已是默认模板，无需启用");
						return;
					}

					/*if (document.getElementsByName("msgTemplateCommunicationEnabledFlg")[i].value == "false" && 
						document.getElementsByName("voiceTemplateCommunicationEnabledFlg")[i].value == "false") {
						alert("该模板的短信或语音方式均未设定'通信启用'，无法启用作为默认模板");
						return;
					}*/
					document.getElementById("enableKey").value = document.getElementsByName("cbIds")[i].value;
					break;
				}
			}
		}
		if(confirm("确认启用吗？启用该模板后，原有默认启用的模板将被取消")){
			document.getElementById("formEnableDefault").submit();
		}
	}
</script>